<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-28 23:43:29
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-03-29 00:31:03
 */


namespace backend\controllers\system;

use  backend\controllers\BaseController;
use common\models\forms\ClearCache;
use Yii;

/**
 * Class SiteController
 *
 * @package app\controllers
 */
class SettingsController extends BaseController
{
    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'baidu' => [
                'class' => \yii2mod\settings\actions\SettingsAction::class,
                'view' => 'baidu',
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \common\models\forms\Baidu::class,
            ],
            'wxapp' => [
                'class' => \yii2mod\settings\actions\SettingsAction::class,
                'view' => 'wxapp',
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \common\models\forms\Wxapp::class,
            ],
            'wechatpay' => [
                'class' => \yii2mod\settings\actions\SettingsAction::class,
                'view' => 'wechatpay',
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \common\models\forms\Wechatpay::class,
            ],
            'weburl' => [
                'class' => \yii2mod\settings\actions\SettingsAction::class,
                'view' => 'weburl',
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \common\models\forms\Weburl::class,
            ],
            'sms' => [
                'class' => \yii2mod\settings\actions\SettingsAction::class,
                'view' => 'sms',
                // also you can use events as follows:
                'on beforeSave' => function ($event) {
                    // your custom code
                },
                'on afterSave' => function ($event) {
                    // your custom code
                },
                'modelClass' => \common\models\forms\Sms::class,
            ]
        ];
    }


    /**
     * 清理缓存
     *
     * @return string
     */
    public function actionClearCache()
    {
        $this->layout = "@backend/views/layouts/main-base";

        $model = new ClearCache();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->goHome();
        } else {
        }

        return $this->render($this->action->id, [
            'model' => $model
        ]);
    }
}
